﻿<UserControl x:Class="CustomerManagement.WorkerList.CustomerListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal" Margin="10">
            <TextBlock VerticalAlignment="Center">Customer Name:</TextBlock>
            <TextBox Name="SearchTextBox" MinWidth="150" Margin="10,0,10,0" />
            <Button Command="{Binding SearchCommand}"
                    CommandParameter="{Binding ElementName=SearchTextBox,Path=Text}">Search</Button>
        </StackPanel>

        <toolkit:DataGrid Grid.Column="0" Grid.Row="1" AutoGenerateColumns="False" AlternationCount="2"
                          IsReadOnly="True"
                          ItemsSource="{Binding CustomerList}">
            <toolkit:DataGrid.Columns>
                <toolkit:DataGridTextColumn Binding="{Binding CustomerID}" Header="Customer ID"/>
                <toolkit:DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
            </toolkit:DataGrid.Columns>
            <toolkit:DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <Grid Background="LightYellow">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Column="0" Grid.Row="0" Text="Customer ID: " />
                        <TextBlock Grid.Column="0" Grid.Row="1" Text="Name.:" />

                        <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Path=CustomerID}" />
                        <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Path=Name}" />
                        
                        <Button Content="Show Rentals" Grid.Column="2" Grid.Row="0" Grid.RowSpan="2"
                                Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type toolkit:DataGrid}},Path=DataContext.ShowRentalsCommand}"
                                CommandParameter="{Binding}"
                                IsEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type toolkit:DataGrid}}, Path=DataContext.IsRentManagementModulePresent}"/>
                    </Grid>

                </DataTemplate>
            </toolkit:DataGrid.RowDetailsTemplate>
        </toolkit:DataGrid>
    </Grid>
</UserControl>
